//
//  BVUpgradeViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/8/4.
//  Copyright © 2017年 YYKJ. All rights reserved.
//  升级VIP

#import "BVUpgradeViewController.h"

@interface BVUpgradeViewController ()

@property (nonatomic ,strong) NSMutableArray    *buttonArray;
@property (nonatomic ,strong) UIButton          *selectButton;

@end

@implementation BVUpgradeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setTitle:@"升级VIP"];
    
    [self layoutUI];
}

-(void)layoutUI{
    
    UIView *bgView = [[UIView alloc]init];
    [self.view addSubview:bgView];
    [bgView setBackgroundColor:[UIColor whiteColor]];
    bgView.sd_layout
    .topSpaceToView(self.view, 10)
    .leftSpaceToView(self.view, 10)
    .rightSpaceToView(self.view, 0)
    .heightIs(135);
    
    UILabel *label = [[UILabel alloc]init];
    [bgView addSubview:label];
    [label setFont:[UIFont systemFontOfSize:14]];
    [label setTextAlignment:NSTextAlignmentLeft];
    [label setTextColor:[UIColor BVTextGrayColor]];
    [label setAttributedText:[self labelWithText:@"12个月 日均1.06元" start:0 end:4]];
    label.sd_layout
    .topSpaceToView(bgView, 0)
    .leftSpaceToView(bgView, 10)
    .heightIs(45);
    [label setSingleLineAutoResizeWithMaxWidth:150];
    
    UIButton *btn1 = [self btnWithTitle:@"¥98" tag:0];
    [bgView addSubview:btn1];
    btn1.sd_layout
    .topSpaceToView(bgView, 0)
    .rightSpaceToView(bgView, 10)
    .widthIs(100)
    .heightIs(45);
    
    self.selectButton = btn1;
    [self.selectButton setSelected:YES];
    
    UIView *lineOne= [[UIView alloc]init];
    [bgView addSubview:lineOne];
    [lineOne setBackgroundColor:[UIColor BVLineGrayColor]];
    lineOne.sd_layout
    .topSpaceToView(label, 0)
    .leftSpaceToView(bgView, 10)
    .rightSpaceToView(bgView, 10)
    .heightIs(1.0);
    
    UILabel *label2 = [[UILabel alloc]init];
    [bgView addSubview:label2];
    [label2 setFont:[UIFont systemFontOfSize:14]];
    [label2 setTextAlignment:NSTextAlignmentLeft];
    [label2 setTextColor:[UIColor BVTextGrayColor]];
    [label2 setAttributedText:[self labelWithText:@"3个月 日均3.8元" start:0 end:3]];
    label2.sd_layout
    .topSpaceToView(lineOne, 0)
    .leftSpaceToView(bgView, 10)
    .heightIs(45);
    [label2 setSingleLineAutoResizeWithMaxWidth:150];
    
    UIButton *btn2 = [self btnWithTitle:@"¥68" tag:1];
    [bgView addSubview:btn2];
    btn2.sd_layout
    .topSpaceToView(lineOne, 0)
    .rightSpaceToView(bgView, 10)
    .widthIs(100)
    .heightIs(45);
    
    UIView *lineTwo= [[UIView alloc]init];
    [bgView addSubview:lineTwo];
    [lineTwo setBackgroundColor:[UIColor BVLineGrayColor]];
    lineTwo.sd_layout
    .topSpaceToView(label2, 0)
    .leftSpaceToView(bgView, 10)
    .rightSpaceToView(bgView, 10)
    .heightIs(1.0);
    
    UILabel *label3 = [[UILabel alloc]init];
    [bgView addSubview:label3];
    [label3 setFont:[UIFont systemFontOfSize:14]];
    [label3 setTextAlignment:NSTextAlignmentLeft];
    [label3 setTextColor:[UIColor BVTextGrayColor]];
    [label3 setAttributedText:[self labelWithText:@"1个月 日均8.2元" start:0 end:3]];
    label3.sd_layout
    .topSpaceToView(lineTwo, 0)
    .leftSpaceToView(bgView, 10)
    .heightIs(45);
    [label3 setSingleLineAutoResizeWithMaxWidth:150];
    
    UIButton *btn3 = [self btnWithTitle:@"¥40" tag:2];
    [bgView addSubview:btn3];
    btn3.sd_layout
    .topSpaceToView(lineTwo, 0)
    .rightSpaceToView(bgView, 10)
    .widthIs(100)
    .heightIs(45);
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:loginBtn];
    [loginBtn setTitle:@"确认支付" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginBtn setBackgroundColor:[UIColor BVBaseOrangeColor]];
    [loginBtn.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
    [loginBtn addTarget:self action:@selector(bindingBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn.layer setMasksToBounds:YES];
    [loginBtn.layer setCornerRadius:5.0];
    loginBtn.sd_layout
    .topSpaceToView(bgView, 30)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(40);
    
    _buttonArray = [NSMutableArray arrayWithObjects:btn1,btn2,btn3, nil];
}

-(void)bindingBtnClick{
    
    
}

-(void)chooseBtnClick:(UIButton *)btn{
    
    [self.selectButton setSelected:NO];
    self.selectButton = _buttonArray[btn.tag];
    [self.selectButton setSelected:YES];
}

-(UIButton *)btnWithTitle:(NSString *)title tag:(NSInteger )tag{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [btn setTitleColor:[UIColor BVTextDarkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor BVBaseOrangeColor] forState:UIControlStateSelected];
    [btn setImage:[UIImage imageNamed:@"huiduihao"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"hongduihao"] forState:UIControlStateSelected];
    [btn setTag:tag];
    [btn addTarget:self action:@selector(chooseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, 50, 0,-50)];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 30)];
    return btn;
}

-(NSMutableAttributedString *)labelWithText:(NSString *)text start:(NSInteger )start end:(NSInteger )end{
    
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:text];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor BVTextDarkGrayColor] range:NSMakeRange(start,end)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(start,end)];
    
    return attributedStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
